package thread2;

import trees.TreeNode;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class IsSymmetric {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return false;
        }

        Queue<TreeNode> queue = new ArrayDeque<>();
        queue.offer(root);

        while (!queue.isEmpty()) {
            int size = queue.size();
            List<Integer> val = new ArrayList<>();
            for (int i = 0; i < size; i++) {
                TreeNode temp = queue.poll();
                if (temp != null) {
                    val.add(temp.val);
                    if (temp.left != null) {
                        queue.offer(temp.left);
                    }

                    if (temp.right != null) {
                        queue.offer(temp.right);
                    }
                }
            }
            System.out.println(val);
        }

        return false;
    }

    public static void main(String[] args) {
        // 构造树
        TreeNode treeNode = new TreeNode(1);
        treeNode.left = new TreeNode(2);
        treeNode.right = new TreeNode(2);

        treeNode.left.left = new TreeNode(3);
        treeNode.left.right = new TreeNode(4);
        treeNode.right.left = new TreeNode(4);
        treeNode.right.right = new TreeNode(3);

        IsSymmetric symmetric = new IsSymmetric();
        System.out.println(symmetric.isSymmetric(treeNode));
    }
}
